package com.chengdu.third.dao;

import com.chengdu.third.pojo.Zwxx;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface IZwxxDao {

    /**
     * 查找所有
     * @return
     */
    @Select("select * from government_mailbox")
    public List<Zwxx> find();

    /**
     * 查找所有市级信件
     * @return
     */
    @Select("select * from government_mailbox where receiving_AREA = '市'")
    public List<Zwxx> findByRec1();

    /**
     * 查找所有区级信件
     * @return
     */
    @Select("select * from government_mailbox where receiving_AREA = '区'")
    public List<Zwxx> findByRec2();

    /**
     * 查找所有乡镇级信件
     * @return
     */
    @Select("select * from government_mailbox where receiving_AREA = '乡镇'")
    public List<Zwxx> findByRec3();

    /**
     * 查找所有村级信件
     * @return
     */
    @Select("select * from government_mailbox where receiving_AREA = '村'")
    public List<Zwxx> findByRec4();

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from government_mailbox where id  = #{id}")
    public void delete(long id);

    /**
     * 根据id修改
     * @param zwxx
     */
    @Update("update government_mailbox set letter_writer = #{letter_writer},phonenumber = #{phonenumber},address = #{address},receiving_AREA = #{receiving_AREA},letter = #{letter} where id = #{id}")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    public void update(Zwxx zwxx);

    /**
     * 增加
     * @param zwxx
     */
    @Insert("insert into  government_mailbox(`id`,`letter_writer`,`phonenumber`,`address`,`receiving_AREA`,`letter`) values(#{id},#{letter_writer},#{phonenumber},#{address},#{receiving_AREA},#{letter})")
    public void add(Zwxx zwxx);

    @Insert("insert into  government_mailbox(`letter_writer`,`phonenumber`,`address`,`receiving_AREA`,`letter`) values(#{letter_writer},#{phonenumber},#{address},#{receiving_AREA},#{letter})")
    public void addbufen(String  letter_writer,String phonenumber,String address,String receiving_AREA,String letter);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from government_mailbox where id = #{id}")
    public Zwxx getZwxxById(long id);
}
